/*
// 文件路径: src/main/java/com/huike/common/aop/OperateLogAspect.java
package com.huike.common.aop;

import com.alibaba.fastjson.JSON;
import com.huike.clues.domain.SysOperLog;
import com.huike.clues.service.ISysOperLogService;

import com.huike.common.Log.OperateLog;
import com.huike.common.utils.ServletUtils;
import com.huike.common.utils.ip.AddressUtils;
import com.huike.common.utils.spring.SpringUtils;

import eu.bitwalker.useragentutils.UserAgent;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.concurrent.CompletableFuture;

@Slf4j
@Aspect
@Component
public class OperateLogAspect {

    private final ISysOperLogService sysOperLogService = SpringUtils.getBean(ISysOperLogService.class);

    @AfterReturning("@annotation(operateLog)")
    public void doAfterReturning(JoinPoint joinPoint, OperateLog operateLog) {
        CompletableFuture.runAsync(() -> saveOperLog(joinPoint, operateLog),
            SpringUtils.getBean("threadPoolTaskExecutor", java.util.concurrent.Executor.class));
    }

    private void saveOperLog(JoinPoint joinPoint, OperateLog operateLog) {
        HttpServletRequest request = ServletUtils.getRequest();

        SysOperLog operLog = new SysOperLog();
        operLog.setTitle(operateLog.value());
        operLog.setBusinessType("ADD"); // 可动态判断
        operLog.setMethod(joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
        operLog.setRequestMethod(request.getMethod());

        UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
        operLog.setOperatorType("PC");

        // 获取登录用户信息（需确保 TokenService 已注入）
        // LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(request);
        // operLog.setOperName(loginUser.getUsername());
        operLog.setOperName("admin"); // 示例，默认值

        operLog.setOperUrl(request.getRequestURI());
        operLog.setOperIp(ServletUtils.getClientIP(request));
        operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));

        operLog.setOperParam(JSON.toJSONString(joinPoint.getArgs()));
        operLog.setStatus(0); // 成功
        operLog.setOperTime(new Date());

        try {
            sysOperLogService.save(operLog);
        } catch (Exception e) {
            log.error("保存操作日志失败：{}", e.getMessage(), e);
        }
    }
}
*/
